<?php
// www.contoh-ta.com
//author : asep setiawan & Team
ini_set('display_errors', 1); ini_set('error_reporting', E_ERROR);
include "../../inc/inc.koneksi.php";
include "../../inc/fungsi_tanggal.php";


if (isset($_GET['getbiaya'])) {
	$run = mysql_query("SELECT * FROM `biaya` ORDER BY `id_biaya` LIMIT 0, 3");
	while ($r = mysql_fetch_array($run)) {
		$data[] = array(
			'nama' => $r['nama_biaya'],
			'info' => $r['info_biaya'],
			'nominal' => 'Rp. ' . number_format($r['nominal_biaya'], 2, ',', '.')
		);
	}
	echo json_encode($data);
	return;
}


$table	= 'siswa';
$id	= $_POST['id'];
$text	= "SELECT * FROM $table WHERE noinduk = '$id'";
$sql 	= mysql_query($text);

$text 	= "SELECT * FROM `wali` WHERE `noinduk` = '$id'";
$sql2 	= mysql_query($text);

$text 	= "SELECT * FROM `pembayaran` WHERE `noinduk` = '$id' AND (`id_perlengkapan` = '1' OR `id_perlengkapan` = '2' OR `id_perlengkapan` = '3') ORDER BY `id_perlengkapan`";
$sql3 	= mysql_query($text);

$text 	= "SELECT * FROM `biaya` ORDER BY `id_biaya` LIMIT 0, 3";
$sql4 	= mysql_query($text);

$text   = "SELECT * FROM spp WHERE noinduk = '$id' AND id_jenis = 1 LIMIT 1";
$sql5   = mysql_query($text);

$row	= mysql_num_rows($sql);
if ($row > 0) {
    while ($r=mysql_fetch_array($sql)){	
	$data['id']         = $r['noinduk'];
	$data['nama']       = $r['nama'];
	$data['jk']         = $r['jenis_kelamin'];
	$data['tempat']     = $r['tempat_lahir'];
	$data['tgl']        = jin_date_str($r['tgl_lahir']);
	$data['alamat']     = $r['alamat_siswa'];
	$data['agama']      = $r['agama'];
	$data['pilihan']    = $r['pilihansekolah'];
	$data['tingkatan']  = $r['tingkat'];
    }

    while ($r = mysql_fetch_array($sql2)) {
	$data['namawali']       = $r['nama_wali'];
	$data['alamatwali']     = $r['alamat_wali'];
	$data['pekerjaanwali']  = $r['pekerjaan'];
	$data['hpwali']         = $r['hp'];
    }

    //$data['pembayaran'] = array();
    while ($r = mysql_fetch_array($sql3)) {
	$data['pembayaran'][] = $r['id_perlengkapan'];
    }

    $i = 0;
    $data['biaya'] = array();
    while ($r = mysql_fetch_array($sql4)) {
        
        $data['biaya'][] = array(
            'nama'      => $r['nama_biaya'],
            'info'      => $r['info_biaya'],
            'nominal'    => ''
        );
        
        $query = mysql_query("SELECT nominal_pembayaran FROM pembayaran WHERE id_perlengkapan = " .$r['id_biaya'] . " AND noinduk = '" .$id. "'");
        while ($rs = mysql_fetch_array($query)) {
            $data['biaya'][$i]['nominal'] = $rs['nominal_pembayaran'];
        }
        
        $i++;
    }
    
    $data['spp'] = '';
    while ($r = mysql_fetch_array($sql5)) {
        $data['spp'] = $r['jumlah'];
    }

    echo json_encode($data);

} else {
    $data['id']		= '';
    $data['nama']	= '';
    $data['jk']		= '';
    $data['tempat']	= '';
    $data['tgl']	= '';
    $data['alamat']	= '';
    $data['hp']		= '';
    echo json_encode($data);
}
?>